package com.github.cakin.shiro.chapter6.realm;

import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.realm.Realm;

/**
 * @className: MyRealm1
 * @description: 自定义Realm
 * @date: 2020/5/20
 * @author: cakin
 */
public class MyRealm1 implements Realm {

    public String getName() {
        return "a"; //realm name 为 “a”
    }

    public boolean supports(AuthenticationToken token) {
        return token instanceof UsernamePasswordToken;
    }

    public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        return new SimpleAuthenticationInfo(
                "cakin3", // 身份 字符串类型
                "123",   // 凭据
                getName() //Realm Name
        );
    }
}
